package com.happytoad.libs.riatrax
{
	import flash.events.MouseEvent;
	
	import mx.controls.Image;

	/**
	 *  The Button component includes automatic Google Analytic tracking.
	 *  <br/><br/>
	 *  Copyright (c) 2009 HappyToad IT Consulting (<a href="http://www.happytoad.com" target="_blank">http://www.happytoad.com</a>)<br/>
     *  Created by Rich Tretola (<a href="http://blog.everythingflex.com" target="_blank">http://blog.everythingflex.com</a>)<br/>
	 *  
	 *  @mxml
	 *
	 *  <p>The <code>&lt;rx:Image&gt;</code> tag inherits all of the
	 *  tag attributes of its superclass,  and adds the following tag attributes:</p>
	 *
	 *  <pre>
	 *  &lt;rx:Image
	 *    <strong>Properties</strong>
	 *    gaCategory="any"
	 *    gaAction="any"
	 *    gaLabel="any"
	 *    gaValue="1"
	 *    gaMode="unique|all|none"
	 *    &gt;
	 *  </pre>
	 * 
	 * 	@includeExample examples/ImageExample.mxml
	 * 
	 *  @see com.happytoad.libs.riatrax.Tracker
	 */


	public class Image extends mx.controls.Image
	{
		include "SharedInclude.as";
		/**
     	 *  Constructor.
     	 */
		public function Image()
		{
			super();
			this.addEventListener(MouseEvent.CLICK,clicked);
		}
		/**
	     *  @private
	     *  EventListener for MouseEvent.CLICK
	     *  calls trackIt
	     *  if no gaCategory is supplied, className will be recorded
	     *  if no gaAction is supplied, event.type will be recorded
	     *  if no gaLabel is supplied, source will be recorded
	     */
		private function clicked(event:MouseEvent):void{
			var o:com.happytoad.libs.riatrax.Image = event.currentTarget as com.happytoad.libs.riatrax.Image;
			trackIt(gaCategory != null ? gaCategory : o.className,
				    gaAction != null ? gaAction : event.type,
				    gaLabel != null ? gaLabel : o.source.toString(),
				    gaValue);
		}
	}
}